Skip to content

docs: Rust CDK language landing page#22

Merged
marc0olo merged 2 commits into
mainfrom
docs/languages-rust
Mar 18, 2026
Merged

docs: Rust CDK language landing page#22
marc0olo merged 2 commits into
mainfrom
docs/languages-rust

Conversation

@marc0olo
Copy link
Copy Markdown
Member

Summary

  • Overview of the Rust CDK and its crate ecosystem (ic-cdk, ic-cdk-macros, ic-cdk-timers)
  • Minimal counter canister example with query + update
  • Getting started with icp-cli and the @dfinity/rust recipe, including Cargo.toml setup
  • Complete canister macro reference (endpoint, lifecycle, system macros)
  • Async support and inter-canister call patterns
  • Data persistence strategies (stable structures vs pre/post upgrade hooks)
  • Wasm limitations and workarounds table
  • Cross-links to stable structures, testing, data persistence, and Motoko pages

Sync recommendation

informed by dfinity/cdk-rs ic-cdk/README.md, dfinity/portal docs/building-apps/developer-tools/cdks/rust/

@marc0olo
Copy link
Copy Markdown
Member Author

Review: Rust CDK language landing page

Must fix

  • icp new my_project --template rust is not valid: Should be icp new my_project (prompts interactively) or icp new my_project --subfolder <name> --define backend_type=rust. There is no --template flag. (Source: .sources/icp-cli/docs/reference/cli.md:1227)

  • icp start --background is not a valid command: Should be icp network start -d. (Source: .sources/icp-cli/docs/migration/from-dfx.md:90, .sources/icp-cli/docs/quickstart.md:31)

  • ic_cdk::call() is deprecated since 0.18.0: The inter-canister call example uses ic_cdk::call(canister, "greet", ("World",)) but this function is deprecated. The new API is ic_cdk::call::Call::bounded_wait(canister, "greet") builder pattern. Since this page targets current development, it should use the non-deprecated API. (Source: .sources/cdk-rs/ic-cdk/src/api/call.rs:468-472)

  • ic_cdk::api::call::accept_message() path is deprecated: Should be ic_cdk::api::accept_message(). The api::call::accept_message re-export is deprecated since 0.18.0. (Source: .sources/cdk-rs/ic-cdk/src/api/call.rs:898-902, .sources/cdk-rs/ic-cdk/src/api.rs:257)

  • ic_cdk::api::management_canister::main::raw_rand() path is wrong: The current path is ic_cdk::management_canister::raw_rand(). The old api::management_canister::main path is deprecated. (Source: .sources/cdk-rs/ic-cdk/src/management_canister.rs)

  • cargo install ic-wasm is incorrect: Per .sources/icp-cli-recipes/recipes/rust/README.md:35, ic-wasm is included with the icp-cli installation. No separate cargo install needed. Only candid-extractor needs separate installation.

  • Unused imports in call example: The snippet imports encode_args and decode_one but uses neither — ic_cdk::call handles serialization internally.

Suggestions

  • ic_cdk::spawn is deprecated since 0.18.0: Should be ic_cdk::futures::spawn. (Source: .sources/cdk-rs/ic-cdk/src/lib.rs:77)

  • register_custom_getrandom! is from the getrandom crate, not ic-cdk: The macro exists and is used in ICP projects (confirmed in .sources/examples/), but the page implies it's an ic-cdk feature. Clarify it comes from the getrandom crate.

  • Both Motoko and Rust pages have sidebar: order: 1: One should be adjusted so sidebar ordering is deterministic.

  • Content brief gap — Candid type mapping: The brief mentions "message types and how they map to Rust functions." The macro table covers this partially but could be more explicit about how Candid types map to Rust types (e.g., natcandid::Nat, textString).

Verified

  • All macros exist: #[query], #[update], #[init], #[pre_upgrade], #[post_upgrade], #[heartbeat], #[inspect_message], #[on_low_wasm_memory], export_candid!() (.sources/cdk-rs/ic-cdk-macros/src/lib.rs:46-96)
  • ic-cdk = "0.19" and candid = "0.10" versions correct (.sources/cdk-rs/Cargo.toml:35,41)
  • Rust recipe @dfinity/rust and config keys (package, shrink) verified
  • ic_cdk::api::time() returns u64 confirmed
  • All 7 internal links resolve to existing files
  • No dfx references, plain .md, no JSX
  • Wasm limitations table is accurate and covers the key pain points developers hit
  • Crate table (ic-cdk, ic-cdk-macros, ic-cdk-timers, candid, ic-stable-structures) is accurate

- Fix CLI commands: icp new --template → --subfolder, icp start → icp network start -d
- Remove ic-wasm from prerequisites (included with icp-cli)
- Update inter-canister call example to Call::bounded_wait builder API (non-deprecated)
- Fix accept_message path: api::call::accept_message → api::accept_message
- Fix raw_rand path: api::management_canister::main → management_canister
- Update spawn to ic_cdk::futures::spawn (non-deprecated)
- Clarify register_custom_getrandom! comes from getrandom crate
- Remove unused candid imports from call example
- Set sidebar order to 2 (Motoko is 1)
- Add Quickstart to further reading, remove duplicate data persistence link
@marc0olo
Copy link
Copy Markdown
Member Author

Feedback addressed:

  • Fixed CLI commands: icp new --template rust--subfolder rust, icp start --backgroundicp network start -d
  • Removed ic-wasm from prerequisites (included with icp-cli installation)
  • Updated inter-canister call example from deprecated ic_cdk::call() to Call::bounded_wait() builder API
  • Fixed accept_message path from deprecated ic_cdk::api::call::accept_message() to ic_cdk::api::accept_message()
  • Fixed raw_rand path from deprecated ic_cdk::api::management_canister::main::raw_rand() to ic_cdk::management_canister::raw_rand()
  • Updated ic_cdk::spawn to non-deprecated ic_cdk::futures::spawn (in code example, callout, and Wasm limitations table)
  • Clarified register_custom_getrandom! comes from getrandom crate, not ic-cdk
  • Removed unused encode_args/decode_one imports from call example
  • Set sidebar order to 2 (Motoko is 1)
  • Added Quickstart to further reading, removed duplicate data persistence link

@marc0olo marc0olo merged commit 43cf2f8 into main Mar 18, 2026
1 check passed
@marc0olo marc0olo deleted the docs/languages-rust branch March 18, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant